package com.dddd.mybatisplusgenerator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Collections;

/**
 * @author 喵星球的大橘
 */
@SpringBootApplication
@ConfigurationProperties(prefix = "generator")
public class GeneratorApplication {


    public static void main(String[] args) {

        String path = "D:\\temp_download\\blog-generator";
        String directory = "blog-recommend";
        String module = "blogrec";
        String dbName="blog_rms";
        String tableName="rms_friend_recommend";
        String tablePrefix="rms_";

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/"+dbName+"?characterEncoding=utf8","root","root")
                .globalConfig(builder -> {
                    builder.author("dddd")
                            .fileOverride()
                            .outputDir(path+"\\"+directory+"\\src\\main\\java")
                            .enableSwagger();
                })
                .packageConfig(builder -> {
                    builder.parent("com.dddd.blog")
                            .moduleName(module)
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, path+"\\"+directory+"\\src\\main\\resources\\mapper"));
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tableName) // 设置需要生成的表名
                            .addTablePrefix(tablePrefix) // 设置过滤表前缀
                            .mapperBuilder()
                            .enableBaseResultMap()
                            .controllerBuilder();

                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }


    public void run(){

    }
}
